try:
    from easysettings import EasySettings
except Exception as e:
    print(e)
    print("YAWK: Failed to init settings, you seem to be missing EasySettings, bailing out.")
    exit(-1)

settings = EasySettings('yawk.config')

def getSetting(key, fallback):
    try:
        if not settings.get(key):
            return fallback
        return settings.get(key)
    except Exception as e:
        print(e)
        return fallback

def getSettingAsBool(key, fallback):
    try:
        if not settings.get(key):
            return fallback
        print("settings.get_bool('" + str(key) + "') -> " + str(settings.get_bool(key)))
        return settings.get_bool(key)
    except Exception as e:
        print(e)
        return fallback

def writeSetting(key, value):
    print(str(key) + " -> " + str(value))
    settings.set(key, value)
    settings.save("yawk.config")

def writeSettingAsBool(key, value):
    bool = False
    if value or value == "1" or value == 1 or value == "true" or value == "True":
        bool = True
    print(str(key) + " -> " + str(value))
    settings.set(key, bool)
    settings.save("yawk.config")

def DEFAULT_HOME_PAGE():
    return "https://startpage.com"

HOME_PAGE = getSetting("general.homepage", DEFAULT_HOME_PAGE())
